package top.jacktgq.hsp.netty.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @Author CandyWall
 * @Date 2020/11/12--15:29
 * @Description 服务器初始化器
 */
public class TestHttpServerinitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        //向管道加入处理器
        //得到管道
        ChannelPipeline pipeline = ch.pipeline();
        //加入一个netty提供的HttpServerCodec codec是 coder-decoder 的缩写
        //1、HttpServerCodec是netty提供的处理Http的编解码器
        pipeline.addLast("MyHttpServerCodec", new HttpServerCodec());
        //增加一个自定义的Handler
        pipeline.addLast("MyHttpServerHandler", new TestHttpServerHandler());
    }
}
